<?php use_javascript('article'); ?>
<div id="actions">
    <ul> 
	<?php if ($sf_user->isAuthenticated()) : ?><li><a href="<?php echo url_for('@new') ?>"><img src="/images/button_new.png" alt="Pridať článok" /></a></li> <?php endif; ?>
	<li><a href="<?php echo url_for('@download') ?>"><img src="/images/button_save.png" alt="Stiahnuť leták" /></a></li>
	<li><a href="<?php echo url_for('@about') ?>"><img src="/images/button_about.png" alt="O projekte" /></a></li>
    </ul>
</div>
<div>

    <?php $articles = $pager->getResults(); ?>

    <?php foreach ($articles as $pos => $article): ?>
	<?php if (($pos % 2) == 1) : ?>
    <div class="row">
	    <?php endif; ?>
	<div class="article" id="pos<?php echo $pos ?>">
	    <div class="title"><h1><?php echo $article->getTitle() ?></h1></div>
	    <div class="article_info">
		<span>autor: <?php echo $article->getUser(); ?></span>
		    <?php if ($sf_user->isAuthenticated()) : ?>
		<span id="<?php echo $article->getID() ?>"> / hodnotenie: <span class="positive_votes" id="<?php echo $article->getId() ?>"><?php echo count($article->getPositiveVotes()) ?></span></span>
			<?php if(Doctrine::getTable('PositiveVote')->hasVoted($sf_user,$article->getID())==false) : ?> <span class="vote_positive" id="<?php echo $article->getID() ?>" > / <a class="vote_positive" id="<?php echo $article->getId() ?>" href="">dôležité!</a></span> <?php endif; ?>
			<?php if(Doctrine::getTable('NegativeVote')->hasVoted($sf_user,$article->getID())==false) : ?> <span class="vote_negative" id="<?php echo $article->getID() ?>"> / <a class="vote_negative" id="<?php echo $article->getId() ?>" href="">nevyhovuje</a></span> <?php endif; ?>
		    <?php endif; ?>
	    </div>
	    <div class="content"><?php echo $article->getContent() ?></div>
	    <div class="source">zdroj: <?php echo $article->getSource() ?></div>
	</div>
	    <?php if ($pos % 2 == 0 | $pos == count($articles)-1) : ?>
    </div>
	<?php endif; ?>

    <?php endforeach; ?>

    <?php if ($pager->haveToPaginate()): ?>

    <div class="pagination_desc">
	<strong><?php echo count($pager) ?></strong> článkov

	    <?php if ($pager->haveToPaginate()): ?>
	- <strong><?php echo $pager->getLastPage() ?></strong> <?php switch($pager->getLastPage()) {
		    case 0: echo "strán";
			break;
		    case 1: echo "strana";
			break;
		    case 2: echo "strany";
			break;
		    case 3: echo "strany";
		break;
	    case 4: echo "strany";
		break;
	    default: echo "strán";
		break;
	} ?>



    </div>

    <div class="pagination">


	<a href="<?php echo url_for('@home') ?>?page=<?php echo $pager->getPreviousPage() ?>">
	    predchádzajúca
	</a>

		<?php foreach ($pager->getLinks() as $page): ?>
	    <?php if ($page == $pager->getPage()): ?>
		<?php echo $page ?>
			<?php else: ?>
        <a href="<?php echo url_for('@home') ?>?page=<?php echo $page ?>"><?php echo $page ?></a>
	    <?php endif; ?>
	<?php endforeach; ?>

	<a href="<?php echo url_for('@home') ?>?page=<?php echo $pager->getNextPage() ?>">
	    ďalšia
	</a>

    </div>
    <?php endif; ?>

<?php endif; ?>

